// packageA/mycomponent/couponLis/couponLis.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    delete_show: {
      type: Boolean,
      value: true
    },
    coupon: {
      type: null
    },
    types: {
      type: null
    },
    combine_show: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
    selectedidx: 1,
    colors: ['#fbbd5c', '#ff8383', '#a291ff', '#f095ed', '#6dccf8', '#fb946c', '#cecece'],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    delteteItem(e) {
      let {
        index,
        item
      } = e.currentTarget.dataset;
      console.log(index, item)
      let urlStr = app.getNetAddresss("coupon.member-coupon.delete");
      urlStr += "&id=" + item.id;

      if (wx.tempCqSwipeCell) {
        wx.tempCqSwipeCell.setData({
          prevBox: 0
        });
      }
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            this.data.coupon.splice(index, 1)

            let arr = this.data.coupon;
            let num = 0;
            arr.forEach(element => {
              num += element.num
            });
            this.triggerEvent('updateDelete', {
              num,
              coupon: this.data.coupon
            })
            wx.showToast({
              icon: 'none',
              title: '操作成功',
              duration: 1000
            });
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1000
            });
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    },
    tapGo(e) {
      if (this.data.selectedidx == '1') {
        let info = e.currentTarget.dataset.info;
        if (this.data.isPresenter) {
          info.isPresenter = this.data.isPresenter;
        }
        if (info.num) {
          wx.navigateTo({
            url: `/packageA/member/coupon_v2_detail/coupon_v2_detail?id=${info.id}&combine=${info.combine}&combine_show=${this.data.combine_show}`,
          });
        } else {
          wx.navigateTo({
            url: `/packageA/member/coupon_v2_detail/coupon_v2_detail?id=${info.id}&combine=${info.combine}&combine_show=${this.data.combine_show}`,
          });
        }
      }
    },
  }
})